import threading as td
import time
exitFlag=0
class myThread (td.Thread):   #继承父类threading.Thread
    def __init__(self,tdname,cnt,idd,delay):
        td.Thread.__init__(self)
        self.name=tdname
        self.cnt=cnt
        self.idd=idd
        self.delay=delay
    def run(self):
        print("线程开始运行"+self.name)
        print_time(self.name, self.cnt,self.delay)
        print ("Exiting " + self.name)
    
def print_time(threadName, cnt, delay):
    while cnt:
        if exitFlag:
            (td.Thread).exit()
        time.sleep(delay)
        print("%s: %s" % (threadName, time.ctime(time.time())))
        cnt -= 1
thread1=myThread("trd1",5,1,2)
thread2=myThread("trd2",10,2,1)
thread1.start()#start采用多线程包中的继承start
thread2.start()